<template>
  <div id="interMethodExternalDiv">
    <Splitpanes horizontal :dbl-click-splitter="false">
      <Pane size="30">
        <vxe-textarea v-model="currentRow.methodDataBase" placeholder="请输入外源sql语句" :autosize="{ minRows: 11, maxRows: 16 }"></vxe-textarea>
      </Pane>
      <Pane size="40" v-if="currentRow.sqlType == 2">
        <vxe-toolbar perfect>
          <template #buttons>
            <vxe-button type="text" class="button-blue" content="新增参数" @click="insertRow"></vxe-button>
            <vxe-button type="text" class="button-blue" content="保存" @click="saveInfo"></vxe-button>
            <vxe-button type="text" class="button-red" content="删除参数" @click="deleteExtParam"></vxe-button>
          </template>
        </vxe-toolbar>
        <div class="tableBox">
          <vxe-table ref="extParamsTableRef" :border="'inner'" show-header-overflow :data="tableList" @current-change="extCurrentRowChange" :row-config="{ isCurrent: true }" :column-config="{ resizable: true }" :edit-config="{ trigger: 'click', mode: 'cell' ,showIcon:false}" height="auto" class="mytable-scrollbar">
            <vxe-column type="seq" width="30" title="#"></vxe-column>

            <vxe-column field="extCode" title="外源参数" :edit-render="{ autofocus: '.vxe-input--inner' }" width="140">
              <template #edit="{ row }">
                <vxe-input v-model="row.extCode" type="text"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="inCodeNo" title="入参" :edit-render="{}" width="80">
              <template #edit="{ row,rowIndex }">
                <VxePulldownSelection :isChild="true" :childIndex="rowIndex" :ref="'fieldRef' + rowIndex" :url="'/api/sys/getInterfaceDictParamList'" @confirmClick="pulldownSelectConfirm" :tableColumn="[
                            { field: 'code', title: '字段' },
                            { field: 'common', title: '出参名称' }
                          ]" :aimKeys="[
                            { aimKey: 'inCodeNo', rowKey: 'code' },
                            { aimKey: 'inCodeId', rowKey: 'id' },
                            { aimKey: 'inCodeNa', rowKey: 'common' },
                            { aimKey: 'inCodeDtype', rowKey: 'coloumType' },
                            { aimKey: 'inCodeDes', rowKey: 'common' },
                            { aimKey: 'inCode', rowKey: 'entity' }
                          ]" :displayTexts="['common']" :displayTextObj="row.inCodeNa ? row.inCodeNa: ''" :dataObj="{dictId: currentRow.interfaceDictId,type:1}" />
              </template>
            </vxe-column>
            <vxe-column field="inCodeNa" title="参数名称" width="85">
              <template #edit="{ row }">
                <vxe-input v-model="row.inCodeNa" type="text"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="extCodeDtype" title="外源参数类型" :edit-render="{}" width="70">
              <template #default="{ row }">
                <span>{{ formatCommon(coloumTypeList, row.extCodeDtype) }}</span>
              </template>
              <template #edit="{ row }">
                <!-- <vxe-input v-model="row.extCodeDtype" type="text" placeholder="外源参数类型"></vxe-input> -->
                <vxe-select v-model="row.extCodeDtype" transfer>
                  <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column field="inCodeDtype" title="入参数据类型" :edit-render="{}" width="70">
              <template #default="{ row }">
                <span>{{ formatCommon(coloumTypeList, row.inCodeDtype) }}</span>
              </template>
              <template #edit="{ row }">
                <vxe-select v-model="row.inCodeDtype" transfer disabled>
                  <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column field="extCodeDes" title="外源参数说明" :edit-render="{}" width="100">
              <template #edit="{ row }">
                <vxe-input v-model="row.extCodeDes" type="text" placeholder="外源参数说明"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="inCodeDes" title="入参说明" :edit-render="{}" width="100">
              <template #edit="{ row }">
                <vxe-input v-model="row.inCodeDes" type="text" placeholder="入参说明"></vxe-input>
              </template>
            </vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane size="40" v-if="currentRow.sqlType == 3">
        <div>
      <vxe-toolbar perfect>
        <template #buttons>
          <vxe-button type="text" class="button-blue" content="新增set参数" @click="insertRowUpdate"></vxe-button>
          <vxe-button type="text" class="button-blue" content="保存" @click="saveInfo"></vxe-button>
          <vxe-button type="text" class="button-red" content="删除参数" @click="deleteUpdateExtParam"></vxe-button>
        </template>
      </vxe-toolbar>
      <div class="tableBox">
        <vxe-table ref="extParamsTableRef" :border="'inner'" show-header-overflow :data="updateTableList" @current-change="extCurrentRowChangeByUpdate" :row-config="{ isCurrent: true }" :column-config="{ resizable: true }" :edit-config="{ trigger: 'click', mode: 'cell' ,showIcon:false}" height="auto" class="mytable-scrollbar">
          <vxe-column type="seq" width="30" title="#"></vxe-column>

          <vxe-column field="extCode" title="外源参数" :edit-render="{ autofocus: '.vxe-input--inner' }" width="140">
            <template #edit="{ row }">
              <vxe-input v-model="row.extCode" type="text"></vxe-input>
            </template>
          </vxe-column>
          <vxe-column field="inCodeNo" title="入参" :edit-render="{}" width="80">
            <template #edit="{ row,rowIndex }">
              <VxePulldownSelection :isChild="true" :childIndex="rowIndex" :ref="'fieldRef' + rowIndex" :url="'/api/sys/getInterfaceDictParamList'" @confirmClick="pulldownSelectConfirmByUpdate" :tableColumn="[
                            { field: 'code', title: '字段' },
                            { field: 'common', title: '出参名称' }
                          ]" :aimKeys="[
                            { aimKey: 'inCodeNo', rowKey: 'code' },
                            { aimKey: 'inCodeId', rowKey: 'id' },
                            { aimKey: 'inCodeNa', rowKey: 'common' },
                            { aimKey: 'inCodeDtype', rowKey: 'coloumType' },
                            { aimKey: 'inCodeDes', rowKey: 'common' },
                            { aimKey: 'inCode', rowKey: 'entity' }
                          ]" :displayTexts="['common']" :displayTextObj="row.inCodeNa ? row.inCodeNa: ''" :dataObj="{dictId: currentRow.interfaceDictId,type:1}" />
            </template>
          </vxe-column>
          <vxe-column field="inCodeNa" title="参数名称" width="85">
            <template #edit="{ row }">
              <vxe-input v-model="row.inCodeNa" type="text"></vxe-input>
            </template>
          </vxe-column>
          <vxe-column field="extCodeDtype" title="外源参数类型" :edit-render="{}" width="70">
            <template #default="{ row }">
              <span>{{ formatCommon(coloumTypeList, row.extCodeDtype) }}</span>
            </template>
            <template #edit="{ row }">
              <!-- <vxe-input v-model="row.extCodeDtype" type="text" placeholder="外源参数类型"></vxe-input> -->
              <vxe-select v-model="row.extCodeDtype" transfer>
                <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
              </vxe-select>
            </template>
          </vxe-column>
          <vxe-column field="inCodeDtype" title="入参数据类型" :edit-render="{}" width="70">
            <template #default="{ row }">
              <span>{{ formatCommon(coloumTypeList, row.inCodeDtype) }}</span>
            </template>
            <template #edit="{ row }">
              <vxe-select v-model="row.inCodeDtype" transfer disabled>
                <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
              </vxe-select>
            </template>
          </vxe-column>
          <vxe-column field="extCodeDes" title="外源参数说明" :edit-render="{}" width="100">
            <template #edit="{ row }">
              <vxe-input v-model="row.extCodeDes" type="text" placeholder="外源参数说明"></vxe-input>
            </template>
          </vxe-column>
          <vxe-column field="inCodeDes" title="入参说明" :edit-render="{}" width="100">
            <template #edit="{ row }">
              <vxe-input v-model="row.inCodeDes" type="text" placeholder="入参说明"></vxe-input>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
    </div>
        <div>
          <vxe-toolbar perfect>
            <template #buttons>
              <vxe-button type="text" class="button-blue" content="新增参数" @click="insertRow"></vxe-button>
              <vxe-button type="text" class="button-red" content="删除参数" @click="deleteExtParam"></vxe-button>
            </template>
          </vxe-toolbar>
          <div class="tableBox">
            <vxe-table ref="extParamsTableRef" :border="'inner'" show-header-overflow :data="tableList" @current-change="extCurrentRowChange" :row-config="{ isCurrent: true }" :column-config="{ resizable: true }" :edit-config="{ trigger: 'click', mode: 'cell' ,showIcon:false}" height="auto" class="mytable-scrollbar">
              <vxe-column type="seq" width="30" title="#"></vxe-column>

              <vxe-column field="extCode" title="外源参数" :edit-render="{ autofocus: '.vxe-input--inner' }" width="140">
                <template #edit="{ row }">
                  <vxe-input v-model="row.extCode" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="inCodeNo" title="入参" :edit-render="{}" width="80">
                <template #edit="{ row,rowIndex }">
                  <VxePulldownSelection :isChild="true" :childIndex="rowIndex" :ref="'fieldRef' + rowIndex" :url="'/api/sys/getInterfaceDictParamList'" @confirmClick="pulldownSelectConfirm" :tableColumn="[
                            { field: 'code', title: '字段' },
                            { field: 'common', title: '出参名称' }
                          ]" :aimKeys="[
                            { aimKey: 'inCodeNo', rowKey: 'code' },
                            { aimKey: 'inCodeId', rowKey: 'id' },
                            { aimKey: 'inCodeNa', rowKey: 'common' },
                            { aimKey: 'inCodeDtype', rowKey: 'coloumType' },
                            { aimKey: 'inCodeDes', rowKey: 'common' },
                            { aimKey: 'inCode', rowKey: 'entity' }
                          ]" :displayTexts="['common']" :displayTextObj="row.inCodeNa ? row.inCodeNa: ''" :dataObj="{dictId: currentRow.interfaceDictId,type:1}" />
                </template>
              </vxe-column>
              <vxe-column field="inCodeNa" title="参数名称" width="85">
                <template #edit="{ row }">
                  <vxe-input v-model="row.inCodeNa" type="text"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="extCodeDtype" title="外源参数类型" :edit-render="{}" width="70">
                <template #default="{ row }">
                  <span>{{ formatCommon(coloumTypeList, row.extCodeDtype) }}</span>
                </template>
                <template #edit="{ row }">
                  <!-- <vxe-input v-model="row.extCodeDtype" type="text" placeholder="外源参数类型"></vxe-input> -->
                  <vxe-select v-model="row.extCodeDtype" transfer>
                    <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
                  </vxe-select>
                </template>
              </vxe-column>
              <vxe-column field="inCodeDtype" title="入参数据类型" :edit-render="{}" width="70">
                <template #default="{ row }">
                  <span>{{ formatCommon(coloumTypeList, row.inCodeDtype) }}</span>
                </template>
                <template #edit="{ row }">
                  <vxe-select v-model="row.inCodeDtype" transfer disabled>
                    <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
                  </vxe-select>
                </template>
              </vxe-column>
              <vxe-column field="extCodeDes" title="外源参数说明" :edit-render="{}" width="100">
                <template #edit="{ row }">
                  <vxe-input v-model="row.extCodeDes" type="text" placeholder="外源参数说明"></vxe-input>
                </template>
              </vxe-column>
              <vxe-column field="inCodeDes" title="入参说明" :edit-render="{}" width="100">
                <template #edit="{ row }">
                  <vxe-input v-model="row.inCodeDes" type="text" placeholder="入参说明"></vxe-input>
                </template>
              </vxe-column>
            </vxe-table>
          </div>
        </div>
      </Pane>
      <Pane size="40" v-if="currentRow.sqlType == 1 || currentRow.sqlType == 4 || currentRow.sqlType == 5">
        <vxe-toolbar perfect>
          <template #buttons>
            <vxe-button type="text" class="button-blue" content="新增参数" @click="insertRow"></vxe-button>
            <vxe-button type="text" class="button-blue" content="保存" @click="saveInfo"></vxe-button>
            <vxe-button type="text" class="button-red" content="删除参数" @click="deleteExtParam"></vxe-button>
          </template>
        </vxe-toolbar>
        <div class="tableBox">
          <vxe-table ref="extParamsTableRef" :border="'inner'" show-header-overflow :data="tableList" @current-change="extCurrentRowChange" :row-config="{ isCurrent: true }" :column-config="{ resizable: true }" :edit-config="{ trigger: 'click', mode: 'cell' ,showIcon:false}" height="auto" class="mytable-scrollbar">
            <vxe-column type="seq" width="30" title="#"></vxe-column>
            <vxe-column field="leftBracket" title="左括号" :edit-render="{ autofocus: '.vxe-input--inner' }" width="65">
              <template #edit="{ row }">
                <vxe-input v-model="row.leftBracket" type="integer"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="extCode" title="外源参数" :edit-render="{ autofocus: '.vxe-input--inner' }" width="140">
              <template #edit="{ row }">
                <vxe-input v-model="row.extCode" type="text"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="symbol" title="比较" :edit-render="{}" width="100">
              <template #default="{row}">
                <div>
                  {{emSymbolArr.filter(data => data.value === row.symbol)[0].label}}
                </div>
              </template>
              <template #edit="{ row }">
                <vxe-select v-model="row.symbol" transfer>
                  <vxe-option v-for="item in emSymbolArr" :key="item.value" :value="item.value" :label="item.label"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column field="inCodeNo" title="入参" :edit-render="{}" width="80">
              <template #edit="{ row,rowIndex }">
                <VxePulldownSelection :isChild="true" :childIndex="rowIndex" :ref="'fieldRef' + rowIndex" :url="'/api/sys/getInterfaceDictParamList'" @confirmClick="pulldownSelectConfirm" :tableColumn="[
                            { field: 'code', title: '字段' },
                            { field: 'common', title: '出参名称' }
                          ]" :aimKeys="[
                            { aimKey: 'inCodeNo', rowKey: 'code' },
                            { aimKey: 'inCodeId', rowKey: 'id' },
                            { aimKey: 'inCodeNa', rowKey: 'common' },
                            { aimKey: 'inCodeDtype', rowKey: 'coloumType' },
                            { aimKey: 'inCodeDes', rowKey: 'common' },
                            { aimKey: 'inCode', rowKey: 'entity' }
                          ]" :displayTexts="['common']" :displayTextObj="row.inCodeNa ? row.inCodeNa: ''" :dataObj="{dictId: currentRow.interfaceDictId,type:1}" />
              </template>
            </vxe-column>
            <vxe-column field="inCodeNa" title="参数名称" width="85">
              <template #edit="{ row }">
                <vxe-input v-model="row.inCodeNa" type="text"></vxe-input>
              </template>
            </vxe-column>
            <!-- <vxe-column field="extCodeNa" title="入参名称" width="180">
              <template #edit="{ row }">
                <vxe-input v-model="row.extCodeNa" type="text"></vxe-input>
              </template>
            </vxe-column> -->
            <vxe-column field="extCodeDtype" title="外源参数类型" :edit-render="{}" width="70">
              <template #default="{ row }">
                <span>{{ formatCommon(coloumTypeList, row.extCodeDtype) }}</span>
              </template>
              <template #edit="{ row }">
                <!-- <vxe-input v-model="row.extCodeDtype" type="text" placeholder="外源参数类型"></vxe-input> -->
                <vxe-select v-model="row.extCodeDtype" transfer>
                  <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column field="inCodeDtype" title="入参数据类型" :edit-render="{}" width="70">
              <template #default="{ row }">
                <span>{{ formatCommon(coloumTypeList, row.inCodeDtype) }}</span>
              </template>
              <template #edit="{ row }">
                <!-- <vxe-input v-model="row.inCodeDtype" type="text" placeholder="入参数据类型"></vxe-input> -->
                <vxe-select v-model="row.inCodeDtype" transfer disabled>
                  <vxe-option v-for="item in coloumTypeList" :key="item.id" :value="item.code" :label="item.name"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column field="extCodeDes" title="外源参数说明" :edit-render="{}" width="100">
              <template #edit="{ row }">
                <vxe-input v-model="row.extCodeDes" type="text" placeholder="外源参数说明"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="extIsNull" title="外源参数允许为空" :edit-render="{}" width="80">
              <template #edit="{ row }">
                <vxe-checkbox v-model="row.extIsNull" content="" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
              </template>
              <template #default="{ row }">
                <vxe-checkbox v-model="row.extIsNull" content="" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
              </template>
            </vxe-column>
            <vxe-column field="inCodeDes" title="入参说明" :edit-render="{}" width="100">
              <template #edit="{ row }">
                <vxe-input v-model="row.inCodeDes" type="text" placeholder="入参说明"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="rightBracket" title="右括号" :edit-render="{ autofocus: '.vxe-input--inner' }" width="65">
              <template #edit="{ row }">
                <vxe-input v-model="row.rightBracket" type="integer"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="relation" title="关系" :edit-render="{}" width="65">
              <template #default="{row}">
                <div>
                  {{[{ value: 'and', label: '并且' },{ value: 'or', label: '或者' }].filter(data => data.value === row.relation)[0].label}}
                </div>
              </template>
              <template #edit="{ row }">
                <vxe-select v-model="row.relation" transfer>
                  <vxe-option v-for="item in [{ value: 'and', label: '并且' },{ value: 'or', label: '或者' }]" :key="item.value" :value="item.value" :label="item.label"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane size="30">
        <vxe-textarea v-model="sqlStrFullTxt" placeholder="外源sql语句" :autosize="{ minRows: 11, maxRows: 16 }"></vxe-textarea>
      </Pane>
    </Splitpanes>
  </div>
</template>
<script setup lang="ts">
// 引入组件区 ==========
import { ref, reactive, getCurrentInstance, onMounted, computed } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue';
import { Splitpanes, Pane } from 'splitpanes';
import moment from 'moment';
let { proxy }: any = getCurrentInstance();
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示
import { isEmpty } from 'lodash';
import { AppStore } from '@/stores/store';
import SelectDataGrid from '@/components/SelectDataGrid.vue';//
import VxePulldownSelection from '@/components/VxePulldownSelection.vue';
import { enums } from '@/enums/enumerator.js';
import { IsEmpty } from '@/utils/common';
import { VXETable, VxeFormPropTypes, VxeFormInstance } from 'vxe-table';

let store = AppStore();
defineExpose({ initPage });
let methodId = null;
let currentRow: any = reactive({});
let currentParamRow: any = reactive({});
let currentParamRowByUpdate: any = reactive({});
let tableList: any[] = reactive([]);
let updateTableList: any[] = reactive([]);
let sqlStr = ref('exec P_Sync_Department');
let sqlStrFull = ref('exec P_Sync_Department @1,@2,@3');
let coloumTypeList = reactive([]);
let emSymbolArr = reactive(enums.emSymbol);
let baseRow = {
  id: null,
  extCode: '',
  extCodeNa: '',
  extCodeDtype: '',
  extCodeDes: '',
  extIsNull: 0,
  symbol: 'equal',
  inCodeId: '',
  inCodeNo: '',
  inCodeNa: '',
  inCodeDtype: '',
  inCodeDes: '',
  isEnable: '',
  seq: '',
  interfaceMethodId: '',
  interfaceId: '',
  interfaceMethodDictId: '',
  leftBracket: 0,
  rightBracket: 0,
  relation: 'and',
  type: 1
};
let baseRowByUpdte = {
  id: null,
  extCode: '',
  extCodeNa: '',
  extCodeDtype: '',
  extCodeDes: '',
  extIsNull: 0,
  symbol: 'equal',
  inCodeId: '',
  inCodeNo: '',
  inCodeNa: '',
  inCodeDtype: '',
  inCodeDes: '',
  isEnable: '',
  seq: '',
  interfaceMethodId: '',
  interfaceId: '',
  interfaceMethodDictId: '',
  leftBracket: 0,
  rightBracket: 0,
  relation: 'and',
  type: 2
};
let sqlType = ref('2');
const extParamsTableRef = ref(null);/**外源参数表格对象 */
const sqlStrFullTxt = computed(() => {
  if (currentRow.sqlType == 2){
    let r = '';
    let str = '';
    let valeStr = '';
    const ars = tableList;
    let arrayStr = [];
    let valueStr = [];
    if (ars && ars.length > 0) {
      for (const iterator of tableList) {

        for (const key in iterator) {
          if (Object.prototype.hasOwnProperty.call(iterator, key)) {
            if (key === 'extCode') {
              arrayStr.push(iterator[key]);
            }
          }
        }
        for (const key in iterator) {
          if (Object.prototype.hasOwnProperty.call(iterator, key)) {
            const element = iterator[key];
            if (key === 'inCodeNo') {
              let repStr = '';
              switch (iterator.extCodeDtype) {
                case '1':
                case '3':
                  repStr = `'#${iterator[key]}#'`;
                  break;
                case '2':
                  repStr = `#${iterator[key]}#`;
                  break;
                default:
                  repStr = `#${iterator[key]}#`;
                  break;
              }
              valueStr.push(repStr);
            }
          }
        }
      }
      str = '('+arrayStr.join(',')+')';
      valeStr = '('+valueStr.join(',')+')';
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '') + '  ' + str +' VALUES ' +valeStr;
    } else {
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '');
    }
    return r;
  } else if (currentRow.sqlType == 3){
    let r = '';
    let i = 0;
    let str = '';
    let valeStr = ' SET ';
    const updateArs = updateTableList;
    const ars = tableList;
    if (updateArs && updateArs.length > 0 && ars && ars.length > 0){
      r = currentRow.methodDataBase ? currentRow.methodDataBase : ''
      updateTableList.map(function (item){
        valeStr += item.extCode +" =";
          let repStr = '';
          switch (item.extCodeDtype) {
            case '1':
            case '3':
              valeStr += `'#${item.inCodeNo}#'` +',';
              break;
            case '2':
              valeStr += `'#${item.inCodeNo}#'` +',';
              break;
            default:
              valeStr += `'#`+item.inCodeNo+`#'`+',';
              break;
          }
      })
      for (const iterator of tableList) {
        if (iterator.extIsNull === 0) {
          let arrayStr = [];
          for (const key in iterator) {
            if (Object.prototype.hasOwnProperty.call(iterator, key)) {
              const element = iterator[key];
              if (key === 'leftBracket') {
                arrayStr[0] = '('.repeat(Number(iterator[key]));
              }
              if (key === 'extCode') {
                arrayStr[1] = ' ' + iterator[key];
              }
              if (key === 'symbol') {
                switch (iterator[key]) {
                  case 'greatthan':
                    arrayStr[2] = ' > ';
                    break;
                  case 'greatequalthan':
                    arrayStr[2] = ' >= ';
                    break;
                  case 'lessthan':
                    arrayStr[2] = ' < ';
                    break;
                  case 'lessequalthan':
                    arrayStr[2] = ' <= ';
                    break;
                  case 'equal':
                    arrayStr[2] = ' = ';
                    break;
                  case 'in':
                    arrayStr[2] = ' in ';
                    break;
                  case 'notin':
                    arrayStr[2] = ' not in ';
                    break;
                  case 'like':
                    arrayStr[2] = ' like ';
                    break;
                  case 'notlike':
                    arrayStr[2] = ' not like ';
                    break;
                  default:
                    break;
                }
              }
              if (key === 'inCodeNo') {
                let repStr = '';
                switch (iterator.extCodeDtype) {
                  case '1':
                  case '3':
                    repStr = `'#${iterator[key]}#'`;
                    break;
                  case '2':
                    repStr = `#${iterator[key]}#`;
                    break;
                  default:
                    repStr = `#${iterator[key]}#`;
                    break;
                }
                arrayStr[3] = ' ' + repStr;
              }
              if (key === 'rightBracket') {
                arrayStr[4] = ')'.repeat(Number(iterator[key]));
              }
              if (key === 'relation') {
                if (i < ars.length - 1) {
                  arrayStr[5] = ' ' + iterator[key] + ' ';
                }
              }
            }
          }
          str += arrayStr.join(' ');
          i++;
        }
      }
      r+= valeStr.substring(0,valeStr.length-1)+ ' where ' + str;
    }else {
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '');

    }
    return r;
  }
  //存储过程类型下 oracle数据库
  else if (currentRow.sqlType == 5 && currentRow.dbMs=='0'){
    let r = '';
    let i = 0;
    let valeStr = '  ';
    const ars = tableList;
    if (ars && ars.length > 0){
      r = currentRow.methodDataBase ? currentRow.methodDataBase : ''
      tableList.map(function (item){
        switch (item.extCodeDtype) {
          case '1':
          case '3':
            valeStr += `'#${item.inCodeNo}#'` +',';
            break;
          case '2':
            valeStr += `'#${item.inCodeNo}#'` +',';
            break;
          default:
            valeStr += `'#`+item.inCodeNo+`#'`+',';
            break;
        }
      })
      r+="("+ valeStr.substring(0,valeStr.length-1)+")";
    }
    else {
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '');

    }
    return r;
  }

  //存储过程类型下 sqlServer数据库
  else if (currentRow.sqlType == 5 && currentRow.dbMs=='1'){
    let r = '';
    let i = 0;
    let valeStr = '  ';
    const ars = tableList;
    if (ars && ars.length > 0){
      r = currentRow.methodDataBase ? currentRow.methodDataBase : ''
      tableList.map(function (item){
        valeStr += item.extCode +" =";
        let repStr = '';
        switch (item.extCodeDtype) {
          case '1':
          case '3':
            valeStr += `'#${item.inCodeNo}#'` +',';
            break;
          case '2':
            valeStr += `'#${item.inCodeNo}#'` +',';
            break;
          default:
            valeStr += `'#`+item.inCodeNo+`#'`+',';
            break;
        }
      })
      r+= valeStr.substring(0,valeStr.length-1);
    }
    else {
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '');

    }
    return r;
  }
  else {
    let r = '';
    let str = '';
    let i = 0;
    const ars = tableList.filter(p => p.extIsNull === 0);
    if (ars && ars.length > 0) {
      for (const iterator of tableList) {
        if (iterator.extIsNull === 0) {
          let arrayStr = [];
          for (const key in iterator) {
            if (Object.prototype.hasOwnProperty.call(iterator, key)) {
              const element = iterator[key];
              if (key === 'leftBracket') {
                arrayStr[0] = '('.repeat(Number(iterator[key]));
              }
              if (key === 'extCode') {
                arrayStr[1] = ' ' + iterator[key];
              }
              if (key === 'symbol') {
                switch (iterator[key]) {
                  case 'greatthan':
                    arrayStr[2] = ' > ';
                    break;
                  case 'greatequalthan':
                    arrayStr[2] = ' >= ';
                    break;
                  case 'lessthan':
                    arrayStr[2] = ' < ';
                    break;
                  case 'lessequalthan':
                    arrayStr[2] = ' <= ';
                    break;
                  case 'equal':
                    arrayStr[2] = ' = ';
                    break;
                  case 'in':
                    arrayStr[2] = ' in ';
                    break;
                  case 'notin':
                    arrayStr[2] = ' not in ';
                    break;
                  case 'like':
                    arrayStr[2] = ' like ';
                    break;
                  case 'notlike':
                    arrayStr[2] = ' not like ';
                    break;
                  default:
                    break;
                }
              }
              if (key === 'inCodeNo') {
                let repStr = '';
                switch (iterator.extCodeDtype) {
                  case '1':
                  case '3':
                    repStr = `'#${iterator[key]}#'`;
                    break;
                  case '2':
                    repStr = `#${iterator[key]}#`;
                    break;
                  default:
                    repStr = `#${iterator[key]}#`;
                    break;
                }
                arrayStr[3] = ' ' + repStr;
              }
              if (key === 'rightBracket') {
                arrayStr[4] = ')'.repeat(Number(iterator[key]));
              }
              if (key === 'relation') {
                if (i < ars.length - 1) {
                  arrayStr[5] = ' ' + iterator[key] + ' ';
                }
              }
            }
          }
          str += arrayStr.join(' ');
          i++;
        }
      }
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '') + '  ' + str;
    } else {
      r = (currentRow.methodDataBase ? currentRow.methodDataBase : '');
    }
    return r;
  }

});


/**页面初始化 */
function initPage(row: any) {
  Object.assign(currentRow, row);
  tableList.length = 0;
  updateTableList.length = 0;
  getDictItemsList();
  findSysInterfaceMethodExtParams();
}
//批量获取字典
async function getDictItemsList() {
  coloumTypeList.length = 0;
  let dictTreeTypeCodes: any = ['interfaceColoumType'];
  const codes = dictTreeTypeCodes.join(',');
  const url = '/api/sys/basDictDetail/findDictDetailListByDictCodes';
  const dictTreeTypeItems: any = await proxy.$http.get(url, { params: { code: codes } });
  const severityType = dictTreeTypeItems.data.find((item) => item.code === 'interfaceColoumType');
  coloumTypeList.push(...severityType.detailDataList);
}
/**获取入参参数对照 */
function findSysInterfaceMethodExtParams() {
  tableList.length = 0;
  const url = '/api/sys/sys-interface-meth-ext-param/findSysInterfaceMethExtParamList';
  proxy.$http
    //注意此处的数据条数
    .get(url, {
      params: { interfaceMethodId: currentRow.id }
    })
    .then((res: any) => {
      if (res && res.data && res.data.length > 0) {

        let queryList= res.data.filter(x=> x.type==1)
        let updateList= res.data.filter(x=> x.type==2)
        Object.assign(tableList, queryList);
        Object.assign(updateTableList, updateList);

        Object.assign(currentParamRow, res.data[0]);
      } else {
        if (currentParamRow && !IsEmpty(currentParamRow.id)) {
          currentParamRow.id = null;
        }
      }
    })
    .catch((err: any) => {
      VxeMessage('获取表格数据异常', VxeNotifyType.error);
    });
}
/**新增条件 */
function insertRow() {
  tableList.push(Object.assign({}, baseRow));
}

/**新增修改 */
function insertRowUpdate() {
  updateTableList.push(Object.assign({}, baseRowByUpdte));
}
/**入参字段选中事件 */
function pulldownSelectConfirm(e) {
  if (e.isChild) {
    e.aimKeys.forEach(m => {
      tableList[e.childIndex][m.aimKey] = e.row[m.rowKey];
    });
  }
}
/**入参字段选中事件 */
function pulldownSelectConfirmByUpdate(e) {
  if (e.isChild) {
    e.aimKeys.forEach(m => {
      updateTableList[e.childIndex][m.aimKey] = e.row[m.rowKey];
    });
  }
}
/**数据类型显示文本 */
function formatCommon(arr, value) {
  for (const item of arr) {
    if (item.code == value) {
      return item.name;
    }
  }
}
/**参数行选中改变 */
function extCurrentRowChange({ row }) {
  Object.assign(currentParamRow, row);
}

/**参数修改行选中改变 */
function extCurrentRowChangeByUpdate({ row }) {
  Object.assign(currentParamRowByUpdate, row);
}
/**保存配置 */
function saveInfo() {
  const url = '/api/sys/sysInterfaceMethod/saveOrUpdateInterfaceMethod';
  const obj: any = {};
  currentRow.methodData = sqlStrFullTxt.value;
  obj.methodList = [currentRow];
  proxy.$http
    .post(url, obj)
    .then((res: any) => {
      //VxeMessage('更新成功', VxeNotifyType.success);
      saveSysInterfaceExtParams();
    })
    .catch((err: any) => {
      VxeMessage('更新失败', VxeNotifyType.success);
    });
}
/**保存参数 */
async function saveSysInterfaceExtParams() {
  let updateRecords = tableList;
  let updateTables = updateTableList;
  updateRecords.forEach(e => {
    e.interfaceId = currentRow.interfaceId;
    e.interfaceMethodId = currentRow.id;
    e.interfaceMethodDictId = e.inCodeId;
  });
  updateTables.forEach(e => {
    e.interfaceId = currentRow.interfaceId;
    e.interfaceMethodId = currentRow.id;
    e.interfaceMethodDictId = e.inCodeId;
  });
  let records = updateRecords.concat(updateTables)
  if (records && records.length > 0) {
    const url = '/api/sys/sys-interface-meth-ext-param/batchSaveSysInterfaceMethExtParam';
    proxy.$http
      .post(url, records)
      .then((res: any) => {
        VxeMessage('更新成功', VxeNotifyType.success);
        proxy.$emit('sucCallBack');
      })
      .catch((err: any) => {
        VxeMessage('更新失败', VxeNotifyType.error);
      });
  } else {
    proxy.$emit('sucCallBack');
  }
}
/**删除参数 */
async function deleteExtParam() {
  if (!currentParamRow || IsEmpty(currentParamRow.id)) {
    VxeMessage('请选中要删除的行', VxeNotifyType.warning);
    return;
  }
  const type = await VXETable.modal.confirm('确定删除选中记录?'); /*不能改el  $confirm 回车事件冒泡你*/
  if (type === 'confirm') {
    const url = `/api/sys/sys-interface-meth-ext-param/deleteSysInterfaceMethExtParam`;
    proxy.$http
      .post(url, currentParamRow)
      .then(async (res: any) => {
        findSysInterfaceMethodExtParams();
      })
      .catch((err: any) => {
        VxeMessage('取消检验失败', VxeNotifyType.error);
      });
  }
}
/**删除修改参数 */
async function deleteUpdateExtParam() {
  if (!currentParamRowByUpdate || IsEmpty(currentParamRowByUpdate.id)) {
    VxeMessage('请选中要删除的行', VxeNotifyType.warning);
    return;
  }
  const type = await VXETable.modal.confirm('确定删除选中记录?'); /*不能改el  $confirm 回车事件冒泡你*/
  if (type === 'confirm') {
    const url = `/api/sys/sys-interface-meth-ext-param/deleteSysInterfaceMethExtParam`;
    proxy.$http
      .post(url, currentParamRowByUpdate)
      .then(async (res: any) => {
        findSysInterfaceMethodExtParams();
      })
      .catch((err: any) => {
        VxeMessage('取消检验失败', VxeNotifyType.error);
      });
  }
}
</script>

<style lang="scss" scoped>
#interMethodExternalDiv {
  height: 100%;

  // 附加按钮间距
  .button-blue,
  .button-red {
    margin: 5px 0 5px 5px;
  }

  //右侧质控项目表格
  .tableBox {
    height: calc(100% - 40px);
    background-color: $base-white;
  }
}
</style>
